<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-us" xml:lang="en-us">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="DC.Type" content="topic">
  <meta name="DC.Title" content="Pod Configuration in the Production Environment for Application-Consistent Backup (MySQL as the Containerized Application)">
  <meta name="product" content="">
  <meta name="DC.Relation" scheme="URI" content="kubernetes_CSI_00062.html">
  <meta name="prodname" content="">
  <meta name="version" content="">
  <meta name="brand" content="30-OceanProtect Appliance 1.5.0-1.6.0 Help Center">
  <meta name="DC.Publisher" content="20241029">
  <meta name="prodname" content="csbs">
  <meta name="documenttype" content="usermanual">
  <meta name="DC.Format" content="XHTML">
  <meta name="DC.Identifier" content="kubernetes_CSI_00067">
  <meta name="DC.Language" content="en-us">
  <link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
  <title>Pod Configuration in the Production Environment for Application-Consistent Backup (MySQL as the Containerized Application)</title>
 </head>
 <body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px">
  <a name="kubernetes_CSI_00067"></a><a name="kubernetes_CSI_00067"></a>
  <h1 class="topictitle1">Pod Configuration in the Production Environment for Application-Consistent Backup (MySQL as the Containerized Application)</h1>
  <div>
   <p>If there are multiple pre-hook or post-hook commands for creating a snapshot for a PVC, you can write multiple pre-executed commands to the same script and place the script in the persistent directory of a container. Running the script to execute multiple commands simplifies the command input process.</p>
   <p>The following shows examples of the script content of the pre-hook or post-hook command. Set <em>password</em> to the actual user password. (For subsequent operations, the pre-script location <strong>/opt/backup/dataprotect_mysql_consistency_pre_script.sh</strong> and the post-script location <strong>/opt/backup/dataprotect_mysql_consistency_post_script.sh</strong> are used as examples. Change the content based on the actual script locations).</p>
   <pre class="screen">#Pre-hook command script
mysql -u root -p <em><strong>password </strong></em>-e "flush tables with read lock;system sleep 300;"</pre>
   <pre class="screen">#Post-hook command script
pid=$(ps -ef | grep "/bin/sh -c<em> /opt/backup/dataprotect</em><em>_</em><em>mysql</em><em>_</em><em>consistency</em><em>_</em><em>pre</em><em>_</em><em>script.sh"</em> | grep -v grep | awk '{print $2}')  
[ ! $pid ] &amp;&amp; echo "pid is null" &amp;&amp; exit
subtree=$(pstree -p $pid) subtree=$(pstree -p $pid)  
right_str=${subtree##*\(}  
sleep_pid=${right_str%*)}  
kill -9 $sleep_pid</pre>
   <div class="section">
    <h4 class="sectiontitle">Procedure</h4>
    <ol>
     <li><span>Upload the script to any persistent directory of the container. Run the following commands on the container page to add permissions to the script file:</span><p></p><pre class="screen">chmod +x <em>/opt/backup/dataprotect_mysql_consistency_pre_script.sh</em>
chmod +x <em>/opt/backup/dataprotect_mysql_consistency_post_script.sh</em></pre>
      <div class="note">
       <img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span>
       <div class="notebody">
        <p>You can also run the <strong>echo</strong> command in the container directory to overwrite or append the script content. The following is an example.</p>
        <pre class="screen">echo "mysql -uroot -p{password} -e "flush tables with read lock;system sleep 300;"" &gt; <em>/opt/backup/dataprotect</em>_<em>mysql</em>_<em>consistency</em>_<em>pre</em>_<em>script.sh</em></pre>
       </div>
      </div> <p></p></li>
     <li><span>Add pod labels and annotations by referring to <a href="kubernetes_CSI_00066.html">Pod Configuration in the Production Environment for Application-Consistent Backup (General)</a>. The following shows examples of the pre-hook or post-hook command values entered when you add annotations:</span><p></p><pre class="screen">#Pre-hook command
kubectl annotate pod -l <strong><em>label=value </em></strong>-n <strong><em>namespace</em></strong> pre.hook.dataprotect.backup.io/command='["/bin/sh", "-c","<em>/opt/backup/dataprotect_mysql_consistency_pre_script.sh</em>"]'
#Post-hook command
kubectl annotate pod -l <strong><em>label=value</em></strong><em> </em>-n <strong><em>namespace</em></strong> post.hook.dataprotect.backup.io/command='["/bin/sh", "-c","<em>/opt/backup/dataprotect_mysql_consistency_post_script.sh</em>"]'</pre>
      <div class="note">
       <img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span>
       <div class="notebody">
        <p>To ensure that the pre-hook or post-hook command can be executed properly, the script location in the command must be the same as the actual upload location of the script.</p>
       </div>
      </div> <p></p></li>
    </ol>
   </div>
  </div>
  <div>
   <div class="familylinks">
    <div class="parentlink">
     <strong>Parent topic:</strong> <a href="kubernetes_CSI_00062.html">FAQs</a>
    </div>
   </div>
  </div>
 </body>
</html>